<template>
	<view>
		<text>{{mess}}</text>
		<view>
			<text>用户名</text>
			<input v-model="user.username" />
		</view>
		<view>
			<text>密码</text>
			<input v-model="user.password" password />
		</view>
		<view>
			<text>确认密码</text>
			<input v-model="user.password2" password />
		</view>
		<button @click="logup">注册</button>
	</view>
</template>

<script>
	import common from '../../common/common.js';
	export default {
		data() {
			return {
				user: {
					username: '',
					password: '',
					password2: ''
				},
				mess: ''
			}
		},
		methods: {
			logup() {
				if (this.user.password != this.user.password2) {
					this.mess = '两次密码不一样';
					return;
				}
				this.myReq({
					url: 'log_up',
					method: "POST",
					data: JSON.stringify(this.user)
				}).then((res) => {
					if (res.data) {
						if (res.data.userID) {
							this.mess = '注册成功';
							uni.setStorageSync('userID', res.data.userID);
							this.userID.id = res.data.userID
							uni.switchTab({
								url: "../my/my"
							})
						} else {
							this.mess = '该用户已经存在'
						}
					} else {
						this.mess = '注册失败'
					}
				})
			}
		}
	}
</script>

<style>
	input {
		background-color: #F8F8F8;
		font-size: 60rpx;
		border: 2rpx solid;
		border-radius: 25rpx;
	}
</style>
